﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace OnlineManagement.Common
{
   public static class SwitchExtend
    {
       public static TOutput Switch<TOutput, TInput>(this TInput input, IEnumerable<TInput> inputSource, IEnumerable<TOutput> outputSource, TOutput defaultOutput)
       {
           IEnumerator<TInput> inputIterator = inputSource.GetEnumerator();
           IEnumerator<TOutput> outputIterator = outputSource.GetEnumerator();

           TOutput result = defaultOutput;
           while (inputIterator.MoveNext())
           {
               if (outputIterator.MoveNext())
               {
                   if (input.Equals(inputIterator.Current))
                   {
                       result = outputIterator.Current;
                       break;
                   }
               }
               else break;
           }
           return result;
       }
    }
}
